<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>借款管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">借款人</div>
                    <div class="field">
                        <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">借款人工号</div>
                    <div class="field">
                        <input name="cstMgrCd" id="cstMgrCd" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="contNo" id="contNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">实际付款金额</div>
                    <div class="field">
                        <input ligerui="width: 82" name="minLoanAmt" id="minLoanAmt" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                        -
                        <input ligerui="width: 82" name="maxLoanAmt" id="maxLoanAmt" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户经理</div>
                    <div class="field">
                        <input name="capCstMgrNm" id="capCstMgrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">所属事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox col_33" id="cstMgrOrgCdId" >
                    <div class="label">所属公司</div>
                    <div class="field">
                        <input name="cstMgrOrgCdCap" id="cstMgrOrgCd" type="text" class="ui-textbox" value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">实际付款时间</div>
                    <div class="field">
                        <input ligerui="width: 82" name="startLoanTm" id="startLoanTm" type="text" class="ui-datepicker"
                               value="">
                        -
                        <input ligerui="width: 82" name="endLoanTm" id="endLoanTm" type="text" class="ui-datepicker"
                               value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">借款类型</div>
                    <div class="field">
                        <select name="loanTypCd"  id="loanTypCd" >
                             <option value="" selected="selected">请选择</option>
                             <c:forEach items="${loanTypCdList}" var="opt">
                              <option value="${opt.code}">${opt.codeNm}</option>
                             </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">流程编号</div>
                    <div class="field">
                        <input name="pNo" id="pNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <%--<div class="fieldBox">
                    <div class="label">所属区域</div>
                    <div class="field">
                        <select name="cstMgrRgnCd"  id="cstMgrRgnCd" >
                            <option value="" selected="selected">请选择</option>
                            <c:forEach items="${regionList}" var="opt">
                                <option value="${opt.code}">${opt.codeNm}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>--%>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>

                    <sys:funcAuth resCd="applyRepay">
                        <input name="hiddenId" id="hiddenId" type="hidden" value="1">
                        <span id="applyRepayBtn" class="sq-button sq-button-round">还款申请</span>
                    </sys:funcAuth>
                </div>
                <div class="clearFix"></div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>



<script type="text/javascript">
    var grid = null, form = null,contractGrid = null;
    $(function () {
        initOrgTree();//所属公司
        initGrid();
        //事业部
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("buOrgCd").setData(${buOrgCdList});
        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
            //detailGrid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            //$("#cstMgrOrgCd").val("");
            //liger.get("cstMgrOrgCd").setValue("");
            //searchOrgTree.clear();
            clearLigerForm("searchBar");
        });

        //还款申请
        $("#applyRepayBtn").click(function (event) {
            var _ids = [];
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            for (var index in selectedRows) {
                if (selectedRows[index].arAmt == null || selectedRows[index].arAmt==0) {
                    $.ligerDialog.SQalert({content: "勾选数据中有待还款金额为0，无需还款，请重新选择", SQ_type: "warning"});
                    return;
                }
                _ids.push(selectedRows[index].payDtlRId);
            }
            var tips ="是否确认发起还款申请?";
            if (_ids.length > 0) {
                var paydtlRIds = _ids.join(',');
            }

            Add_navTab("fin_1"+Date.parse(new Date()), "还款申请",
                '<%=path%>/finance/finRepayApplyInfo/toRepayApplyPage.do?paydtlRIds='+paydtlRIds);
        });
    });

    //发起还款申请
    function repayApply(payDtlRId, arAmt) {
        if (arAmt == null || arAmt == 0) {
            $.ligerDialog.SQalert({content: "待还款金额为0，无需还款", SQ_type: "warning"});
            return;
        }
        var _ids = [];
        _ids.push(payDtlRId);
        var tips ="是否确认发起还款申请?";
        if (_ids.length > 0) {
            var paydtlRIds = _ids.join(',');
        }

        Add_navTab("fin_1"+Date.parse(new Date()), "还款申请",
            '<%=path%>/finance/finRepayApplyInfo/toRepayApplyPage.do?paydtlRIds='+paydtlRIds);
    }

    /* 初始化列表*/
    function initGrid(){
        var url = '<%=path%>/finance/finLoanInfo/initLoanPayList.do';
        grid = $("#ligergrid1").ligerGrid({
                url:url,
                method: 'get',
                columns: [
                    /*{display: '客户名称', name: 'cstNm', minWidth: 200, align: 'left', enabledSort: false, render: function (rowdata, rowindex, value, column) {
                            if(StringUtils.isEmpty(value)){
                                value = "";
                            }
                            var h = '';
                            h='<a href="javascript:showDetail(';
                            h+="'"+rowdata.cstId+"'";
                            h+=')">'+value+'</a>'
                            return h;
                        }},*/
                    {display: '承租人', name: 'cstNm', width: 150, align: 'center', enabledSort: false},
                    {display: '合同号', name: 'contNo', width: 150, align: 'center', enabledSort: false},
                    {display: '支付表', name: 'paySchNo', width: 150, align: 'center', enabledSort: false},
                    {display: '流程编号', name: 'pno', width: 150, align: 'center', enabledSort: false,
                        render: function (rowdata, rowindex, value, column) {
                            if(StringUtils.isEmpty(value)){
                                value = "";
                            }
                            var h = '';
                            h='<a href="javascript:showFlow(';
                            h+="'"+rowdata.pinstId+"',";
                            h+="'"+rowdata.audStsCd+"',";
                            h+="'"+rowdata.dataId+"',";
                            h+="'"+rowdata.formUrl+"'";
                            h+=')">'+value+'</a>'
                            return h;
                        }},
                    {display: '客户经理', name: 'capCstMgrNm', width: 150, align: 'center', enabledSort: false},
                    {display: '所属事业部', name: 'buOrgCd', width: 150, align: 'center', enabledSort: false,
                        render: function (rowdata, index, value) {
                            var buCd = '';
                            if(rowdata.buOrgCd!='0000'){
                                buCd = rowdata.buOrgCd;
                            }
                            return buCd;
                        }
                    },
                    {display: '所属省公司', name: 'prOrgCdNm', width: 150, align: 'center', enabledSort: false},
                    {display: '所属分公司', name: 'cyOrgCdNm', width: 150, align: 'center', enabledSort: false},
                    /*{display: '所属区域', name: 'cstMgrRgnCd',  width: 150, align: 'center', enabledSort: false},*/
                    {display: '借款人', name: 'cstMgrNm', width: 150, align: 'center', enabledSort: false},
                    {display: '借款人工号', name: 'cstMgrCd', width: 150, align: 'center', enabledSort: false},
                    {display: '借款类型', name: 'loanTypCd', width: 150, align: 'center', enabledSort: false},
                    {
                        display: '实际付款金额(元)', name: 'feeAmt', width: 150, align: 'center', enabledSort: false,
                        render: function (rowdata, index, value) {
                            return '&yen;' + FormatMoney(rowdata.feeAmt / 100);
                        }
                    },

                    {display: '实际付款时间', name: 'fCrtTm', width: 100, align: 'center', enabledSort: false,render: renderDate},
                    {
                        display: '待还款金额(元', name: 'arAmt', width: 100, align: 'center', enabledSort: false,
                        render: function (rowdata, index, value) {
                            return '&yen;' + FormatMoney(rowdata.arAmt/100);
                        }
                    },
                    {
                        display: '操作', width: 350, align: 'left', enabledSort: false,
                        render: function (rowdata, index, value) {
                            var hiddenId = $('#hiddenId').val();
                            var h = "";
                            if($("#hiddenId").val()){
                                if (rowdata.arAmt != null && rowdata.arAmt != 0 && hiddenId == 1) {
                                    h = '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="repayApply('+rowdata.payDtlRId+','+rowdata.arAmt+');"><i class="sqBtnIco_50"></i>还款申请</a> ';
                                }
                            }

                            return '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="repayApplyDtl(' + rowdata.id + ',\'' + rowdata.payDtlRId + '\');"><i class="sqBtnIco_49"></i>还款明细</a>  '
                                + h
                        }
                    },
                ],
                pageSize: 10,
                root: 'rows',
                record: 'total',
                hideLoadButton: true,
                width: '100%',
                height: '100%',
                heightDiff: -2,
                allowUnSelectRow: true,
                alternatingRow: false,
               checkbox:true,//列表是否有选择框
               // enabledEdit: true,//是否能编辑
               rownumbers:true,//列表是否有行号

            onBeforeShowData: function () {
                    var grid = this;
                    grid.collapsedRows = [];
                }
            })
        grid.setHeight(100);
        form = $("#searchBar").ligerForm();
    }
    //到流程跟踪页
    function showFlow(pInstId,audStsCd,dataId,formUrl){
        if(StringUtils.isEmpty(pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var params = "?pInsId="+pInstId+"&status="+audStsCd+"&businessKey="+dataId+"&formUrl="+formUrl;
        Add_navTab('finloaninfo'+pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //初始化公司
    var searchOrgTree = null;
    function initOrgTree(){
        var params = {};
        //if(queryFlag=="query"){
            params.userId = '${currentUserId}';
        //}
        params.cstMgrOrgCd = '${currOrg}';
        searchOrgTree = $("#cstMgrOrgCd").ligerComboBox({
            width: 480,
            selectBoxWidth: 480,
            selectBoxHeight: 150,
            //限制只能选叶节点，父节点不能点击
            treeLeafOnly: false,
            valueField: 'orgCd',
            textField: 'orgDispNm',
            showTreePath: true,
            tree: {
                ajaxType: 'get',
                idFieldName:'orgCd',
                textFieldName: 'orgDispNm',
                checkbox: false,
                parentIcon: "none",
                childIcon: "none",
                needCancel : false
            }
        });
        $.ajax({
            type: 'get',
            dataType:'json',
            data: params,
            url: '<%=path%>/project/prjbscinfo/searchBuOrgTree.do',
            success:function(msg){
                if(msg.success == 1){
                    searchOrgTree.treeManager.setData(msg.data);
                    searchOrgTree.clear();
                    searchOrgTree.setValue('${currOrg}');
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });

    }

    /**
     * 还款明细
     * @param payDtlRId
     */
    function  repayApplyDtl(id,payDtlRId){
        Add_navTab('finRePayApplyDetail'+id,'还款明细',"<%=path%>/finance/finRepayApplyInfo/toDetailList.do?payDtlRId="+payDtlRId);
    }
</script>

</body>
</html>
